package top.kaoshanji.q1ch07b;

import top.kaoshanji.y1constant.FileConstant;

import java.io.*;

/**
 * 代码清单-q1ch07b-337页a：演示标准I/O重定向
 * author kaoshanji
 * ^_^
 * create time 2025/3/12 17:39
 */
public class Redirecting {

    static String pathStr = FileConstant.LOCAL_ROOT_PATH.concat("q1ch07b337页a\\");

    public static void main(String[] args) {

        PrintStream console = System.out;

        try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(pathStr.concat("Redirecting.java")));
            PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(pathStr.concat("Redirecting.txt"))))
        ){
            System.setIn(in);
            System.setOut(out);
            System.setErr(out);

            new BufferedReader(new InputStreamReader(System.in)).lines().forEach(System.out::println);

        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            System.setOut(console);
        }

    }


}
